from peewee import *

"""
连接数据库，前提是这个database存在
"""
db = MySQLDatabase("fb_data", host="127.0.0.1", port=3306, user="root", password="123456")


class BaseModel(Model):
    class Meta:
        database = db


# 设计数据表的时候有几个重要点一定要注意
"""
char类型， 要设置最大长度
对于无法确定最大长度的字段，可以设置为Text
设计表的时候 采集到的数据要尽量先做格式化处理
default和null=True
"""


class Interview(BaseModel):
    id = IntegerField(primary_key=True)
    category_id = IntegerField()
    category_name = CharField()
    question = TextField(null=False)
    difficulty = IntegerField(null=True)
    analysis = TextField(null=True)
    answer = TextField(null=True)
    source = TextField(null=True)


class Category(BaseModel):
    id = IntegerField(primary_key=True)
    name = CharField()
    count = IntegerField()


if __name__ == "__main__":
    # db.create_tables([Topic, Answer, Author])
    db.create_tables([Interview])
